#include <iostream>

// #include "IntArray.hpp"

using namespace std;

class Integer {
   private:
    int x;

   public:
    Integer(int x = 0) : x(x) {};
    void print() {
        std::cout << x;
    }
    void print() const {
        std::cout << x;
    }
};

class IntArray {
   private:
    Integer *data;
    int n;

   public:
    IntArray(int n = 1);
    ~IntArray();
    // void print();
    void print() const;
    Integer &operator[](int i);
    const Integer &operator[](int i) const;
};

IntArray::IntArray(int n) : n(n) {
    if (n < 1) {
        n = 1;
    }
    data = new Integer[n];
    for (int i = 0; i < n; i++) {
        data[i] = Integer(i);
    }
    cout << "constructor is executed" << endl;
}

IntArray::~IntArray() {
    cout << "destructor is executed\n";
    delete[] data;
}

Integer &IntArray::operator[](int i) {
    cout << "operator[] is executed\n";
    return this->data[i];
}

const Integer &IntArray::operator[](int i) const {
    cout << "const operator[] is executed\n";
    return this->data[i];
}

void IntArray::print() const {
    cout << "const print:";
    for (int i = 0; i < n; i++) {
        data[i].print();
        if (i != n - 1) cout << " ";
    }
    cout << endl;
}

// void IntArray::print() {
//     cout << "print:";
//     for (int i = 0; i < n; i++) {
//         data[i].print();
//         if (i != n - 1) cout << " ";
//     }
//     cout << endl;
// }
